package com.it.gw.modules.water.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.it.common.utils.StringUtils
import com.it.data.network.rsp.RsvrDetailVo
import com.it.gw.databinding.ItemReservoirSeeBinding


class ReservosirseeAdapter(
    var context: Context,
    var datas: List<RsvrDetailVo>
) : RecyclerView.Adapter<ReservosirseeAdapter.ViewHolder>() {
    companion object {
        const val TAG = "ReservosirseeAdapter"
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        val binding = ItemReservoirSeeBinding.inflate(LayoutInflater.from(parent.context))
        return ViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ViewHolder, @SuppressLint("RecyclerView") position: Int) {
        val bean = datas.get(position)
        //水库名称
        holder.binding.stnm.text = StringUtils.getNoNullData(bean.stnm)
        //库容
        holder.binding.sjkr.text = "设计库容：${StringUtils.getNoNullData(bean.sjkr)}"
        holder.binding.jhkr.text = "校核库容："+StringUtils.getNoNullData(bean.jhkr)


        holder.binding.qntqkr.text = "去年同期：${StringUtils.getNoNullData(bean.qntqkr)}"
        holder.binding.lastdayW.text = "上期库容：${StringUtils.getNoNullData(bean.lastdayW)}"
        holder.binding.w.text = "今日库容：  "+ StringUtils.getNoNullData(bean.w)

        if(bean.w>bean.qntqkr){
            holder.binding.tqb.setTextColor(Color.parseColor("#EB4141"))
        }
        else{
            holder.binding.tqb.setTextColor(Color.parseColor("#32cd32"))
        }


        if(bean.w>bean.lastdayW){
            holder.binding.lastdayRateW.setTextColor(Color.parseColor("#EB4141"))
        }
        else{
            holder.binding.lastdayRateW.setTextColor(Color.parseColor("#32cd32"))
        }




        holder.binding.tqb.text = StringUtils.getNoNullData(bean.tqb)
        holder.binding.lastdayRateW.text = StringUtils.getNoNullData(bean.lastdayRateW)

        //水位
        holder.binding.fsltdz.text = "汛限水位："+StringUtils.getNoNullData(bean.fsltdz)
        holder.binding.fstp.text = "汛期类型："+StringUtils.getNoNullData(bean.fstp)
        holder.binding.lastyearZ.text = "去年同期："+StringUtils.getNoNullData(bean.lastyearZ)
        holder.binding.lastdayZ.text = "上期水位："+StringUtils.getNoNullData(bean.lastdayZ)
        holder.binding.rz.text = "今日水位：   "+StringUtils.getNoNullData(bean.rz)

        if(bean.rz>bean.lastyearZ){
            holder.binding.lastyearRateZ.setTextColor(Color.parseColor("#EB4141"))
        }
        else{
            holder.binding.lastyearRateZ.setTextColor(Color.parseColor("#32cd32"))
        }

        if(bean.rz>bean.lastdayZ){
            holder.binding.lastdayRateZ.setTextColor(Color.parseColor("#EB4141"))
        }
        else{
            holder.binding.lastdayRateZ.setTextColor(Color.parseColor("#32cd32"))
        }




        holder.binding.lastyearRateZ.text = StringUtils.getNoNullData(bean.lastyearRateZ)
        holder.binding.lastdayRateZ.text = StringUtils.getNoNullData(bean.lastdayRateZ)


        //流量
        holder.binding.inq.text = "入库流量："+StringUtils.getNoNullData(bean.inq)
        holder.binding.otq.text = "出库流量："+StringUtils.getNoNullData(bean.otq)


        holder.binding.date.text = StringUtils.getNoNullData(bean.createdTime)





    }

    override fun getItemCount() = datas.size

    class ViewHolder(val binding: ItemReservoirSeeBinding) :
        RecyclerView.ViewHolder(binding.root)
}